package com.example.eventdemo;

import com.example.eventdemo.entity.UserMessage;
import com.example.eventdemo.event.NoticeEvent;
import com.example.eventdemo.publisher.EventPublisher;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

/**
 * 应用启动类
 */
@SpringBootApplication
public class EventDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(EventDemoApplication.class, args);
    }

    /**
     * 启动后执行的测试代码
     */
    @Bean
    public CommandLineRunner run(EventPublisher eventPublisher) {
        return args -> {
            // 模拟用户注册
//            System.out.println("=== 开始用户注册 ===");
//            eventPublisher.register("张三", "zhangsan@example.com");
//            System.out.println("=== 用户注册流程结束 ===");


            Thread.sleep(5000);
            UserMessage u1=new UserMessage();
            u1.setType("type1");
            NoticeEvent ne1=new NoticeEvent(this,u1);
            eventPublisher.push(ne1);

            Thread.sleep(5000);

            UserMessage u2=new UserMessage();
            u1.setType("type2");
            NoticeEvent ne2=new NoticeEvent(this,u1);
            eventPublisher.push(ne2);


        };
    }
}